import { Body, Controller, Post } from '@nestjs/common';
import { UserService } from './user.service';
import { User } from './user.entity'
import { Response } from '../common/Response'

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Post('/findAll')
  async findAll(): Promise<Response<User[]>> {
    try {
      const users = await this.userService.getOnlineUser();
      return {
          code:0,
          status: 'ok',
          data: users
      }
    } catch (error) {
      return {
        code: 1,
        status: 'error',
        msg: '查询失败'
      }
    }
  }

  @Post('/add')
  add(@Body() body): Promise<Response<any>>{
    console.log(body);
    return this.userService.addUser(body)
  }
}